
<!--
 * @description  : 市管-检查-检查作业指导书
 * @descriptionDetail: 市管-检查-检查作业指导书
 * @copyright    : 浙江烟草
 * @author       : sy
 * @create       : 2022-09-10 18:43:02
-->
<template>
  <view class="page">
    <!-- #ifdef H5-ONLY -->
    <theme-navbar
      :is-white="false"
      :title="navTitle"
      :custom-back="goBack"
      style="z-index: 99999"
    >
    </theme-navbar>
    <!-- #endif -->
    <view class="content">
      <view class="wrap">
        <u-swiper img-mode="scaleToFill" :list="imgList" :effect3d="false" mode="rect"></u-swiper>
      </view>
      <view class="c-title">
        {{ checkInfo.taskSubject == CHECK_TASK_SUBJECT.haveLicense ? checkInfo.companyName : `${checkInfo.companyName}(无证户)` }}
      </view>
      <u-gap :height="$theme.cm_gap_height" :bg-color="$theme.cm_gap_color"></u-gap>
      <view style="width: calc(100% - 30px);padding-left: 15px;">
        <form-section title="重点标签"></form-section>
      </view>
      <view class="check-guide-item">
        <view v-if="baseTagInfo.length == 0">
          无标签
        </view>
        <view v-else>
          <u-tag :text="bti.itemName" mode="plain" shape="circle" type="warning" style="margin-right: 5px;" v-for="(bti, idx) in baseTagInfo" :key="idx" />
        </view>
      </view>
      <!-- 风险提示 -->
      <u-card
        :title="gd.name"
        margin="0rpx"
        border-radius="70"
        :head-style="headStyle"
        :body-style="bodyStyle"
        v-for="(gd, idx) in commonDatas"
        :key="idx"
        :border="false"
      >
        <view slot="body">
          <view v-if="gd.data.length == 0">
            无
          </view>
          <view v-else>
            <u-tag :text="gdd.itemName" mode="plain" shape="circle" type="warning" style="margin-right: 5px;" v-for="(gdd, gdidx) in gd.data" :key="gdidx" />
          </view>
        </view>
      </u-card>
      <!-- 流出问题 -->
      <u-card title="流出问题" :border="false" margin="0rpx" border-radius="70" :head-style="headStyle" :body-style="bodyStyle">
        <view slot="body">
          <view v-if="cigOutList.length == 0">
            无
          </view>
          <view v-else>
            <u-table>
              <u-tr>
                <u-th width="50%">
                  外流品规
                </u-th>
                <u-th>外流数量</u-th>
                <u-th>查获时间</u-th>
              </u-tr>
              <u-tr v-for="(c, cIdx) in cigOutList" :key="cIdx">
                <u-td width="50%" class="table-overflow">
                  {{ c.goodsName }}
                </u-td>
                <u-td>{{ c.qty }}</u-td>
                <u-td>{{ c.caseDate }}</u-td>
              </u-tr>
            </u-table>
          </view>
        </view>
      </u-card>
      <!-- 案件信息 -->
      <u-card title="案件信息" :border="false" margin="0rpx" border-radius="70" :head-style="headStyle" :body-style="bodyStyle">
        <view slot="body">
          <view v-if="caseInfo.length == 0">
            无
          </view>
          <view v-else>
            <u-table>
              <u-tr>
                <u-th width="50%">
                  名称
                </u-th>
                <u-th>案值(元)</u-th>
                <u-th>案发时间</u-th>
              </u-tr>
              <u-tr v-for="(c, cIdx) in caseInfo" :key="cIdx">
                <u-td width="50%" class="table-overflow">
                  {{ c.caseName }}
                </u-td>
                <u-td>{{ c.caseTotalVal }}</u-td>
                <u-td>{{ c.caseDate }}</u-td>
              </u-tr>
            </u-table>
          </view>
        </view>
      </u-card>
      <!-- 关联零售户 -->
      <u-card title="关联零售户" :border="false" margin="0rpx" border-radius="70" :head-style="headStyle" :body-style="bodyStyle">
        <view slot="body">
          <view v-if="relRetailers.length == 0">
            无
          </view>
          <view v-else>
            <u-table>
              <u-tr>
                <u-th>关联人</u-th>
                <u-th>许可证号</u-th>
                <u-th>关系</u-th>
              </u-tr>
              <u-tr v-for="(rr, rIdx) in relRetailers" :key="rIdx">
                <u-td>{{ rr.managerName || rr.companyName || '&nbsp;' }} </u-td>
                <u-td>{{ rr.licNo || '&nbsp;' }} </u-td>
                <u-td>{{ rr.relationName || '&nbsp;' }} </u-td>
              </u-tr>
            </u-table>
          </view>
        </view>
      </u-card>
      <!-- 规范经营问题、许可证问题、违规问题、线索登记 -->
      <u-card
        :title="gd.name"
        margin="0rpx"
        border-radius="70"
        :head-style="headStyle"
        :body-style="bodyStyle"
        v-for="(gd) in guideDatas"
        :key="gd.uuid"
        :border="false"
      >
        <view slot="body">
          <view v-if="gd.data.length == 0">
            无
          </view>
          <view v-else>
            <u-tag :text="gdd.itemName" mode="plain" shape="circle" type="warning" style="margin-right: 5px;" v-for="(gdd, gdidx) in gd.data" :key="gdd.val_name + gdidx" />
          </view>
        </view>
      </u-card>
    </view>

    <view class="space-content"></view>
    <view class="submit-btns btn-other-cls">
      <u-button class="del" style="width: 99%;" type="primary" :disabled="time > 0" size="medium" @click="handlerSubmit">
        {{ time > 0 ? readTxt + time : readTxt }}
      </u-button>
    </view>
  </view>
</template>
<script>
/**
 * 检查作业指导书
 */
import checkService from "@/service/check/check.service"
import certService from "@/service/certificate/certificate.service"
import commonService from '@/service/eCigar/common.service'
import util from "@/common/util.js";
import {CHECK_TASK_SUBJECT,} from "@/common/common_enum.js";
import FormSection from "@/components/form-section.vue";
import {CHECK_GUIDE_ENMU,} from "@/service/check/mapping/enum.js"
export default {
  components: { FormSection,},
  data() {
    return {
      menuItemCountMap: {}, // 检查作业指导书信息
      checkInfo: this.getRouteParam(),
      retailerUuid: "", // 零售户uuid
      retailer: {},
      imgList: [],  // 展示的零售户照片
      headStyle: {
        fontWeight: 600,
      },
      bodyStyle: {
        paddingTop: 5,
      },
      readTxt: '请阅读',
      time: 3,
      commonDatas: [],  // 指导书中与检查重点平级信息
      guideDatas: [],   // 指导书信息
      caseInfo: [], // 案件信息
      cigOutList:[], // 流出问题
      complaintData: {},  // 投诉举报数据
      baseTagInfo: [],// 标签数据
      relGis: [],      // 关联高危区域
      relRetailers: [],  // 关联经营户
      CHECK_TASK_SUBJECT,
      taskSubject:'',
    }
  },
  onLoad(option) {
    this.retailerUuid = option.retailerUuid;
    this.taskSubject = option.taskSubject;
  },
  mounted () {
    let intev = setInterval(() => {
      this.time = this.time - 1;
      if (this.time == 0) {
        clearInterval(intev);
        this.readTxt = '开始检查';
      }
    }, 600);
    this.queryPortraitInfo();
    this.initCheckGuide({});
    this.queryImgs();
  },
  methods: {
    // 查询持证户或无证户画像信息
    queryPortraitInfo() {
      // 00000000000000000000000001013108
      this.$u.loading("加载中...");
      checkService.getCheckGuidance(this.retailerUuid).then(dr => {
              this.$u.hideLoading();
              if (dr.success) {
                let portraitData = dr.bean;
                commonService.getBusLicInfoByRetailerUuid(this.retailerUuid).then(dr => {
                console.log("getBusLicInfoByRetailerUuid",dr);
                  if(dr.success) {
                    if(dr.bean){
                      let licenseGuide = new Array();
                      if(dr.bean.tyshxydm){
                        if(dr.bean.companyName != dr.bean.qyjgmc.replace(/（个体工商户）/,'')) {
                          licenseGuide.push({itemName:"字号名称不符"})
                        }
                        if(dr.bean.managerName!= dr.bean.fddbr) {
                          licenseGuide.push({itemName:"负责人（经营者）姓名不符"})
                        }
                        if(!dr.bean.optoEndYear<1) {
                          licenseGuide.push({itemName:"营业执照即将到期"})
                        } else if(!dr.bean.opto != dr.bean.businessEnd && dr.bean.businessEndYear<5) {
                          licenseGuide.push({itemName:"营业执照有效期不一致"})
                        } 
                        if(dr.bean.businessAddr!= dr.bean.zs) {
                          licenseGuide.push({itemName:"经营场所不符"})
                        }
                        if(dr.bean.djztzwmc && dr.bean.djztzwmc.indexOf("存续")== -1) {
                          licenseGuide.push({itemName:"营业执照"+dr.bean.djztzwmc})
                        }
                      }else {
                        licenseGuide.push({itemName:"营业执照信息不存在"})
                      }
                      
                      console.log(licenseGuide);
                      let businessLicData = {"91302":licenseGuide};
                      portraitData = Object.assign(portraitData, businessLicData);
                      this.initCheckGuide(portraitData);
                      
                    }
                  }
                });
              } else {
                this.$u.toast(dr.msg);
              }
            });
    },
    // 处理检查作业指导书数据
    initCheckGuide(checkGuideData) {
      this.baseTagInfo = checkGuideData[CHECK_GUIDE_ENMU.CASE_PROBLEM] || [];// 涉案问题  就是重点检查
      this.cigOutList = checkGuideData.cigOutList || [];
      this.commonDatas = [
        this.addGuideDatas(checkGuideData, "风险提示", CHECK_GUIDE_ENMU.EXECUTION_RISK),  // 风险提示
      ];
      // 案件信息
      this.caseInfo = checkGuideData.caseList ? checkGuideData.caseList : [];
      this.guideDatas = [
        this.addGuideDatas(checkGuideData, "规范问题", CHECK_GUIDE_ENMU.SPECIFICATION_BUSINESS_PROBLEM),  // 规范经营问题 91303对应项itemType91303
        this.addGuideDatas(checkGuideData, "证照问题", CHECK_GUIDE_ENMU.LIC_PROBLEM),  // 许可证问题 91302对应项itemType91302
      ];

      this.relRetailers = checkGuideData.relRetaulerList || [];
    },
    // 向作业指导书对象中添加渲染数据
    addGuideDatas(checkGuideData, guideName, guideType) {
      let datas = checkGuideData[guideType];
      return {name: guideName, data: datas || [], uuid: util.uuid(),};
    },
    // 查询展示的零售户照片
    queryImgs() {
      let jgRoot = `${commonService.baseUrl}/commonfile/filestore/downloadOnlineFile.do?tk=${uni.getStorageSync("tk")}&fileUrl=`;
      let zmRoot = `${commonService.baseUrl}/commonfile/filestore/downloadFile.do?tk=${uni.getStorageSync("tk")}&fileId=`;
      Promise.all([checkService.jgPlatformPicture(this.retailerUuid), checkService.getPictureByRetailerUuid({retailerUuid:this.retailerUuid,taskSubject:this.taskSubject,}),]).then(drs => {
        // 经管照片
        if (drs[0].success) {
          let jgPic = drs[0].data[0] || {};
          jgPic.jg_store_image && this.imgList.push({image: jgRoot + encodeURIComponent(jgPic.jg_store_image),});
          jgPic.jg_counter_image && this.imgList.push({image: jgRoot + encodeURIComponent(jgPic.jg_counter_image),});
          jgPic.jg_cust_image && this.imgList.push({image: jgRoot + encodeURIComponent(jgPic.jg_cust_image),});
          jgPic.jg_lice_image && this.imgList.push({image: jgRoot + encodeURIComponent(jgPic.jg_lice_image),});
          jgPic.jg_back_counter_image && this.imgList.push({ image: jgRoot + encodeURIComponent(jgPic.jg_back_counter_image), });
        }
        // 零售户照片
        if (drs[1].success) {
          let reta = drs[1].bean || {};
          reta.storeImageUuid && this.imgList.push({image: zmRoot + reta.storeImageUuid,});
          reta.counterImageUuid && this.imgList.push({image: zmRoot + reta.counterImageUuid,});
          reta.custImageUuid && this.imgList.push({image: zmRoot + reta.custImageUuid,});
          reta.liceImageUuid && this.imgList.push({image: zmRoot + reta.liceImageUuid,});
          reta.backCounterImageUuid && this.imgList.push({image: zmRoot + reta.backCounterImageUuid,});
        }
        // 如果没有照片，显示一个无照片
        console.log(this.imgList);
        if (this.imgList.length == 0) {
          this.imgList.push({image: require("../../static/check/nophoto.png"),});
        }
      });
    },
    // 提交检查任务
    handlerSubmit() {
      this.setRouteParam(this.checkInfo);
      this.$u.route({
        url:'/pages/check/checkDetail',
        type:'redirectTo',
      })
    },
  },
}
</script>
<style lang="scss" scoped>
.page{padding: 0;}
.content {
  background-color: #FFF;
  .c-title {
    opacity: .8;
    color: #000;
    font-weight: 600;
    font-size: 16px;
    //text-align: center;
    width: 100%;
    z-index: 99;
	padding: 20px;
  }
}
.table-overflow {
  white-space:nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.check-guide-item {
  margin-top: 8px;
  padding: 5px 15px;
}
.divide-gap {
  background-color: #F3F3F4;
  font-size: 18px;
  color: #666;
  height: 48px;
  line-height: 48px;
  font-weight: 600;
  padding-left: 15px;
  border-radius: 20px;
}
.pd{
	padding: 0 $cm-conent-padding-column;
	width: 100%;
}
/deep/.u-td{
	white-space: inherit !important;
	height: auto !important;
}
</style>
